package com.ukao.pad.ui.myData;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.RadioButton;

import com.ukao.pad.R;
import com.ukao.pad.base.BaseFragment;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.Unbinder;
import me.yokeyword.fragmentation.SupportFragment;


public class MyDataTabFragment extends BaseFragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @BindView(R.id.yesterday_btn)
    RadioButton yesterdayBtn;
    @BindView(R.id.today_btn)
    RadioButton todayBtn;
    @BindView(R.id.seven_days_btn)
    RadioButton sevenDaysBtn;
    @BindView(R.id.one_days_month_btn)
    RadioButton oneDaysMonthBtn;
    @BindView(R.id.three_days_month_btn)
    RadioButton threeDaysMonthBtn;
    @BindView(R.id.one_year_btn)
    RadioButton oneYearBtn;
    @BindView(R.id.fame_layout)
    FrameLayout fameLayout;
    Unbinder unbinder;


    private String mParam1;
    private String mParam2;
    private SupportFragment[] mFragments=new SupportFragment[6] ;

    public static MyDataTabFragment newInstance(String param1, String param2) {
        MyDataTabFragment fragment = new MyDataTabFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        Log.d("调用了？", "onCreateView: ");
        View view = inflater.inflate(R.layout.fragment_my_data_tab, container, false);
        unbinder = ButterKnife.bind(this, view);

        return view;
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        initView();
    }

    @Override
    protected void initView() {
        for (int i = 0; i < mFragments.length; i++) {
            mFragments[i]= MyDataFragment.newInstance(String.valueOf(i+1),"");
        }


        loadMultipleRootFragment(R.id.fame_layout, 0,
                mFragments);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnCheckedChanged({R.id.yesterday_btn, R.id.today_btn, R.id.seven_days_btn, R.id.one_days_month_btn, R.id.three_days_month_btn, R.id.one_year_btn})
    public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
        if (checked) {
            switch (buttonView.getId()) {
                case R.id.yesterday_btn:
                    showHideFragment(mFragments[0]);
                    break;
                case R.id.today_btn:
                    showHideFragment(mFragments[1]);
                    break;
                case R.id.seven_days_btn:
                    showHideFragment(mFragments[2]);
                    break;
                case R.id.one_days_month_btn:
                    showHideFragment(mFragments[3]);
                    break;
                case R.id.three_days_month_btn:
                    showHideFragment(mFragments[4]);
                    break;
                case R.id.one_year_btn:
                    showHideFragment(mFragments[5]);
                    break;
            }
        }
    }
}
